package com.waimai1.waimai.config;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;

import com.wechat.pay.java.core.util.PemUtil;
import lombok.Data;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.PrivateKey;
import java.security.Security;

@Data
public class PayConfig {
    private final static String  merchantId="1598019071";
    private final static String  merchantSerialNumber="2576F3312AEAF7DCAEEE404B6B5FB2838A8317B9";
    private final static String  apiV3key="IOxbNqaOWnBc0skl17151Xy89mIdYU5k";
//    private final static String  appid="wx4fe2775ae7278ade";
    public  static Config config;

    static {
        try {
            config = new RSAAutoCertificateConfig.Builder()
                    .merchantId(merchantId)
                    .privateKeyFromPath(getPath())
                    .merchantSerialNumber(merchantSerialNumber)
                    .apiV3Key(apiV3key)
                    .build();
        } catch (IOException e) {
            throw new RuntimeException();
        }
    }
    public static String getPath() throws IOException {
        File filepath = new File("cert");
        Path parentPath = Paths.get(filepath.getCanonicalPath());
        // 文件保存路径
        return parentPath.resolve("apiclient_key.pem").toString();
    }
}
